package com.tencent.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tencent.entity.Order;
import com.tencent.entity.Result;

import com.tencent.service.LoginService;
import com.tencent.service.OrderHistoryService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;


import java.util.List;

/**
 * @author: @date: 2022/8/31 15:26
 * @description:
 */
@RestController
@RequestMapping("/orderhistory")
@Api(tags="预约历史模块")
public class OrderHistoryController {
    @Autowired
    private OrderHistoryService orderHistoryService;

    @Autowired
    private LoginService loginService;

//    @Autowired
//    private OrderHistoryMapper orderHistoryMapper;

    @GetMapping
    @ApiOperation("获取所有预约历史")
    private Result findAll() {
        
//        System.out.println(id);
//        String authorization = request.getHeader("Authorization");
//        System.out.println(authorization);
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        String username = (String) authentication.getPrincipal();
//        System.out.println(username);
        Integer id = loginService.findIdByUsername(username);
//        Object o = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
//        System.out.println(o.getClass());
//        System.out.println("拿id:" + o);



        List<Order> orders = orderHistoryService.findAllById(id);

//        IPage<Order> page = new Page<>();
//        page.setCurrent(2);
//        page.setSize(2);
//        orderHistoryService.page(page);
        orders.forEach(order -> System.out.println(order));
        return Result.success(orders);

    }

    @RequestMapping ("deleteOrder")
    @ApiOperation("根据用户id删除预约历史")
    @ApiImplicitParam(name = "id",value = "预约id参数")
    private Result deleteOrder(Integer id) {
//        System.out.println(id);

        boolean b = orderHistoryService.removeById(id);
      //  int i = orderHistoryMapper.deleteById(id);
        return Result.success(b);
    }
}